package org.rednebula.framework.core.web.action;

import org.rednebula.framework.core.ProcedureEngine;
import org.rednebula.framework.core.log.Log;
import org.rednebula.framework.core.model.form.BasicForm;
import org.rednebula.framework.core.utils.ReflectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Controller
@Scope("prototype")
public abstract  class BasicAction<T extends BasicForm> extends ActionSupport implements ModelDriven<T>, Preparable {

	@Autowired
	ProcedureEngine procedureEngine;
	
	protected static Log log=Log.getLog(BasicAction.class);
	
	BasicForm businessForm;
	
	public  String AJAXJSON="ajaxjson";

	
	public BasicAction() {
		super();
		// TODO Auto-generated constructor stub
	}

	public BasicForm getBusinessForm() {
		return businessForm;
	}

	public void setBusinessForm(BasicForm businessForm) {
		this.businessForm = businessForm;
	}

	public ProcedureEngine getProcedureEngine() {
		return procedureEngine;
	}

	public void setProcedureEngine(ProcedureEngine procedureEngine) {
		this.procedureEngine = procedureEngine;
	}

	public T getModel() {
		return (T)businessForm;
	}

	public void prepare() throws Exception {
		getProcedureEngine().getEnvironment();
		Class cls= ReflectionUtils.getSuperClassGenricType(this.getClass());
		BasicForm form=(BasicForm)cls.newInstance();
		this.setBusinessForm(form);
	}
	
	public void dd(){
		
	}
	
	public String save(){
		return "";
	}
	
}
